package com.olap.starter.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.olap.starter.core.base.BaseService;
import com.olap.starter.mapper.TableOperationButMapper;
import com.olap.starter.pojo.TableConfig;
import com.olap.starter.pojo.TableOperationBut;
import com.olap.starter.pojo.TreeConfig;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author WBG
 * @since 2022-08-31
 */
@Service
@DS("online")
public class TableOperationButServices extends BaseService<TableOperationButMapper, TableOperationBut> {

    public void saveList(List<TableOperationBut> operationBut, TableConfig tableConfig) {
        if(operationBut == null){
            return;
        }
        for (TableOperationBut tableOperationBut : operationBut) {
            tableOperationBut.setParentId(tableConfig.getId());
            tableOperationBut.setVersion(tableConfig.getVersion());
            tableOperationBut.setType("0");
            tableOperationBut.setId(null);
            save(tableOperationBut);
        }
    }

    public void saveList(List<TableOperationBut> operationBut, TreeConfig treeConfig) {
        if(operationBut == null){
            return;
        }
        for (TableOperationBut tableOperationBut : operationBut) {
            tableOperationBut.setParentId(treeConfig.getId());
            tableOperationBut.setId(null);
            tableOperationBut.setVersion(treeConfig.getVersion());
            tableOperationBut.setType("1");
            save(tableOperationBut);
        }
    }
}
